package org.as3search {
	/*
	 * as3search - http://code.google.com/p/as3search
	 * Copyright (c) 2009-2010 by respective authors. All rights reserved.
	 *
	 * This library is free software; you can redistribute it and/or modify it under the
	 * terms of the GNU Lesser General Public License as published by the Free Software
	 * Foundation; either version 2.1 of the License, or (at your option) any later
	 * version.
	 *
	 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
	 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
	 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
	 *
	 * You should have received a copy of the GNU Lesser General Public License along
	 * with this library; if not, write to the Free Software Foundation, Inc.,
	 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
	 */
	
	import org.flexunit.Assert;
	
	import org.as3search.config.FlexSearchConfiguration;
	import org.as3search.config.LightSearchConfiguration;
	import org.as3search.criteria.Criteria;
	import org.as3search.criteria.impl.CriteriaImpl;
	import org.as3search.providers.ArraySearchProvider;
	
	/**
	 * 
	 */
	public class SearchTestCase {
		
		public function SearchTestCase() {
		
		}
		
		[After]
		public function tearDown():void {
			Search.configuration = new LightSearchConfiguration();
		}
		
		[Test]
		public function testConfiguration():void {
//			test reasonable defaults
			Assert.assertNotNull("'Search.configuration' should never be null by default",
				Search.configuration);
			Assert.assertTrue("'Search.configuration' should support Array by default",
				Search.configuration.getSearchProvider([]) is ArraySearchProvider);
//			test assignment
			var config:FlexSearchConfiguration = new FlexSearchConfiguration();
			Search.configuration = config;
			Assert.assertTrue("could not set 'Search.configuration'",
				Search.configuration === config);
		}
		
		[Test]
		public function testWithin():void {
			var criteria:Criteria = Search.within([{id: 0}]);
			Assert.assertNotNull("within() should never return null",
				criteria);
			Assert.assertEquals("failed to inject the correct configuration into the returned criteria",
				Search.configuration, criteria.configuration);
			Assert.assertTrue("did not return an appropriate provider",
				CriteriaImpl(criteria).provider is ArraySearchProvider);
		}
	}
}